package StudyCode.summary.myfile;

import javax.swing.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class SerializeObjectToFile {
	public static void main(String[] args) {
		serializeObject(new JButton(), "E:/Copy/1.txt");
	}

	private static void serializeObject(Object object, String filename) {
		System.out.println("开始序列化 " + filename);
		try {
			FileOutputStream fileOut = new FileOutputStream(filename);
			ObjectOutputStream out = new ObjectOutputStream(fileOut);
			out.writeObject(object);
			out.close();
			fileOut.close();
		} catch (IOException ex) {
			ex.printStackTrace();
		}
		System.out.println("序列化结束 " + filename);
	}
}
